package com.basker.pisces.domain.event;

import org.springframework.util.Assert;

import com.basker.pisces.domain.command.CommandExecuteContext;
import com.basker.pisces.domain.command.CommandResult;
import com.basker.pisces.domain.command.meta.Command;
import com.basker.pisces.domain.entity.meta.Entity;

import lombok.Getter;

/**
 * 命令完成执行后发布的事件
 *
 * @author hangwen
 */
@Getter
public class CommandExecutedDomainEvent extends DomainEvent {

    private static final long serialVersionUID = -1314100256719431984L;

    private CommandExecuteContext context;

    /**
     * 命令的结果
     */
    private CommandResult result;

    /**
     * 执行的业务对象
     */
    private Object[] dataObjects;

    public CommandExecutedDomainEvent(Object source, CommandExecuteContext context, Object[] dataObjects,
                                      CommandResult result) {
        super(source);

        Assert.isTrue(source instanceof Entity, "CommandEvent 'source' should be an Entity");
        Assert.notNull(context, "parameter 'context' isrequired");

        this.context = context;
        this.dataObjects = dataObjects;
        this.result = result;
    }

    public Command getCommand() {
        return this.context.getCommand();
    }

    public Entity getEntity() {
        return (Entity) this.source;
    }

}
